package com.cloudatum.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cloudatum.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 订单控制器
 * Created by zhoujian on 2015/10/29.
 */
@RequestMapping("order")
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("inOrder")
    public Map inOrder(HttpServletRequest request){
        return orderService.inOrder(request.getSession().getId());
    }

    @RequestMapping("doOrder")
    public Map doOrder(String _s,String code,String phone){
        Map<String,String> map = new HashMap<>();
        int result = orderService.doOrder(_s,code,phone,map);
        map.put("code",result+"");
        return map;
    }

    @RequestMapping(value = "completeOrder",method = RequestMethod.POST,produces = {MediaType.APPLICATION_JSON_VALUE})
    public Map completeOrder(@RequestBody()String jsonStr){
        JSONObject jo = JSON.parseObject(jsonStr);
        String uuid = jo.getString("uuid");
        String contact = jo.getString("contact");
        String address = jo.getString("address");
        String remark = jo.getString("remark");
        return orderService.completeOrder(uuid,contact,address,remark);
    }



}
